package com.dy.controller;

import com.dy.pojo.User;
import com.dy.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述)
 * @Date: 2021/4/8 9:47
 * @Version 1.0 (版本)
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/selectById/{uid}")
    @HystrixCommand(fallbackMethod = "hystrixGet")
    public User getUser(@PathVariable Integer uid){
        System.out.println("--------hystrix--selectById");
        User users = userService.selectById(uid);
        if (users == null) {
            throw new RuntimeException("uid=>"+uid+"。。不存在用户，或者无法找到");
        }
        return users;
    }
    //备用方法
    public User hystrixGet(@PathVariable Integer uid){
        return new User().setUid(uid)
                .setUname("没用找到该用户，null---@Hystrix")
                .setDatas("no this database in MySQL");
    }
}
